<?php
/* Used by the editClient.php class to draw information from the database. It
 * also holds the form data.
 * @AUTHOR: Donald Barclay, Nicolas DaLomba
 */

include_once('database/dbClient.php');
include_once('domain/Client.php');
    
function retrieveClientByID($cid){
        connect();
        $query = "SELECT * FROM dbClient WHERE id LIKE '%" . $cid . "%'";
    $result = mysql_query($query);
    if (mysql_num_rows($result) != 1) {
    	mysql_close();
        return false;
    }
    $result_row = mysql_fetch_assoc($result);
    $theEntry = new Client($result_row['id'], $result_row['first_name'], $result_row['last_name'],
                    $result_row['ssn'], $result_row['gender'], $result_row['birthday'], $result_row['phone1'],
                    $result_row['phone2'], $result_row['status'], $result_row['medication_taken'], 
                    $result_row['admission_physical_notes'], $result_row['discharge_physical_notes']);
    mysql_close();
    return $theEntry;
        
}

function findID($fn,$ln){
    connect();
        $query = "SELECT clientID FROM dbClient WHERE first_name && last_name LIKE '%" . $fn . "%' && '%". ln ."%'";
    $result = mysql_query($query);
    if (mysql_num_rows($result) != 1) {
    	mysql_close();
        return false;
    }
    $result_row = mysql_fetch_assoc($result);
    $theEntry = new Client($result_row['id'], $result_row['first_name'], $result_row['last_name'],
                    $result_row['ssn'], $result_row['gender'], $result_row['birthday'], $result_row['phone1'],
                    $result_row['phone2'], $result_row['status'], $result_row['medication_taken'], 
                    $result_row['admission_physical_notes'], $result_row['discharge_physical_notes']);
    mysql_close();
    return $theEntry->get_clientID();
}

function editClient($clientID){
    $client = retrieveClientByID($clientID);
                                     if (!$_GET('clientID')==""){
                                         $client->set_clientID($_GET('clientID'));
                                     }
                                     if (!$_GET('first_name')==""){
                                         $client->set_first_name($_GET('first_name'));
                                     }
                                     if (!$_GET('last_name')==""){
                                         $client->set_last_name($_GET('last_name'));
                                     }
                                     if (!$_GET('ssn')==""){
                                         $client->set_SSN($_GET('ssn'));
                                     }
                                     if (!$_GET('gender')==""){
                                         $client->set_gender($_GET('gender'));
                                     }
                                     if (!$_GET('birthday')==""){
                                         $client->set_birthday($_GET('birthday'));
                                     }
                                     if (!$_GET('phonePrimary')==""){
                                         $client->set_phone1($_GET('phonePrimary'));
                                     }
                                     if (!$_GET('phoneSecondary')==""){
                                         $client->set_phone2($_GET('phoneSecondary'));
                                     }
                                     if (!$_GET('status')==""){
                                         $client->set_status($_GET('status'));
                                     }
                                     if (!$_GET('medication_taken')==""){
                                         $client->set_medication_taken($_GET('medication_taken'));
                                     }
                                     if (!$_GET('admitNotes')==""){
                                         $client->set_admission_physical_notes($_GET('admitNotes'));
                                     }
                                     if (!$_GET('dischargeNotes')==""){
                                         $client->set_discharge_physical_notes($_GET('dischargeNotes'));
                                     }
}
?>

<form method="POST">
    <input type="hidden" name="old_id" value=<?PHP echo("\"" . $id . "\""); ?>>
    <input type="hidden" name="old_pass" value=<?PHP echo("\"" . $client->get_password() . "\""); ?>>
    <input type="hidden" name="_form_submit" value="1">
    <p>(<span style="font-size:x-small;color:FF0000">*</span> denotes required fields)
    <p> First Name<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="first_name" tabindex="1" value="<?PHP echo($client->get_first_name()) ?>">
        Last Name<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="last_name" tabindex="2" value="<?PHP echo($client->get_last_name()) ?>">
        
        <fieldset> 
        <legend>Contact Information:</legend>
        <p>Address<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="address" tabindex="3" size=40 value="<?PHP echo($client->get_address()) ?>">
        City<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="city" tabindex="4" value="<?PHP echo($client->get_city()) ?>">
        <p>State<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="state" tabindex="4" value="<?PHP echo($client->get_state()) ?>">
        <p>Zip Code<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="zip" tabindex="4" value="<?PHP echo($client->get_zipcode()) ?>">
        <p>Primary Phone Number<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="phone1" tabindex="4" value="<?PHP echo($client->get_phone1()) ?>">
        <p>Secondary Phone Number<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="phone2" tabindex="4" value="<?PHP echo($client->get_phone2()) ?>">
        </fieldset>
    
        <fieldset>
        <legend>Personal Information:</legend>
        <p>Social Security Number<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="ssn" tabindex="3" size=40 value="<?PHP echo($client->get_SSN()) ?>">
        Date of Birth<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="dob" tabindex="4" value="<?PHP echo($client->get_birthday()) ?>">
        <p>Gender<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="gender" tabindex="3" size=40 value="<?PHP echo($client->get_gender()) ?>">
        </fieldset>
                
        <fieldset>
        <legend>Appointment Information:</legend>
        <p>Status:<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="status" tabindex="3" size=40 value="<?PHP echo($client->get_status()) ?>">
        Medication Taken:<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="meds_taken" tabindex="4" value="<?PHP echo($client->get_medication_taken()) ?>">
        <p>Admission Physical Notes:<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="apn" tabindex="3" size=40 value="<?PHP echo($client->get_admission_physical_notes()) ?>">
        <p>Discharge Physical Notes:<span style="font-size:x-small;color:FF0000">*</span>: <input type="text" name="dpn" tabindex="3" size=40 value="<?PHP echo($client->get_discharge_physical_notes()) ?>">
        </fieldset>
